<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
	Class Name	: zetro_func
	Purpose		: function classes
	Author		: Iswan Putera S.Kom
	Date		: May 2013
	Version		: 1.0.0
*/
class zetro_func extends zetro_manager
{
	function __construct()
	{
		parent::__construct();
		$this->CI=& get_instance();
		$this->CI->load->library('zetro_auth');
		$this->CI->load->model('main_model');
	}
	
	function active_user($users='')
	{
		$this->user=$users;	
	}
	
	function menus($menu)
	{
		$this->menu=$menu;
	}
	
	function reg_number($reg_num)
	{
		$this->reg_num=$reg_num;
	}
	
	function get_modul_approver($lvl='0')
	{
		$data=array();$level='';
		$this->CI->main_model->table_name('v_app_doc');
		$this->CI->main_model->set_methods('select');
		$this->CI->main_model->query();
		$this->CI->main_model->where(array('id_doc'=>$this->menu));
		$data=$this->CI->main_model->set_data();
		foreach($data as $r)
		{
			switch($lvl)
			{
				case '0':	
				$level=$r->level_1;
				break;
				case '1':	
				$level=$r->level_2;
				break;
				case '2':	
				$level=$r->level_3;
				break;
				case '3':	
				$level=$r->level_4;
				break;
			}
		}
		return $level;
	}
	
	function get_app_level($field='app_level',$tabel='v_app_level')
	{
		$data=array();$app_level='';//$field='';
		$this->CI->main_model->table_name($tabel);
		$this->CI->main_model->set_methods('select');
		$this->CI->main_model->query();
		$this->CI->main_model->where(array('id_reg'=>$this->reg_num));
		$data=$this->CI->main_model->set_data();
		foreach($data as $r)
		{
			$app_level=$r->$field;
		}
		return $app_level;
	}
	
	function set_approval($tp='')
	{
		$usr=$this->get_modul_approver($this->get_app_level());
		$sts=$this->get_app_level('app_stat');
		$icon=($this->CI->session->userdata('userid')==$usr && $sts!='D')?
			  'cus-cog':'cus-zoom';
		$aksi=($this->CI->session->userdata('userid')==$usr && $sts!='D')?
			  'approval':'detail';
		return ($tp=='')?$icon:$aksi;
	}
//new method
	function table_name($table)
	{
		$this->tables=$table;
	}
	function field_name($fld)
	{
		$this->fields=$fld;
	}
	function wherex($where)
	{
		$this->wheres=$where;	
	}
	function get_app_levels()
	{
		$data=array();$app_level='';//$field='';
		$this->CI->main_model->table_name($this->tables);
		$this->CI->main_model->set_methods('select');
		$this->CI->main_model->query();
		$this->CI->main_model->where($this->wheres);
		$data=$this->CI->main_model->set_data();
		$fld=$this->fields;
		foreach($data as $r)
		{
			$app_level=$r->$fld;
		}
		return $app_level;
	}


	function set_approvals($stat_fld='',$tp='')
	{
		$icon="";
		$usr=$this->get_modul_approver($this->get_app_levels());
		$this->field_name($stat_fld);	
		$sts=$this->get_app_levels();
		$icon=($this->CI->session->userdata('userid')==$usr && $sts!='D')? 'cus-cog':'cus-zoom';
		$aksi=($icon=='cus-cog')? 'approval':'detail';
		echo $icon;
		return ($tp=='')?$icon:$aksi;	
	}
	
// end of zetro_func class
}